# -*- coding: utf-8 -*-
"""
Created on Wed May 27 21:02:54 2020

@author: zhryyshr
"""


import requests
import json
import time
import fake_useragent as fu    #动态的浏览器标识
ua = fu.UserAgent()
header = {'User-Agent':ua.random }
from bs4 import BeautifulSoup
import pandas as pd
import numpy as np
import os
os.chdir(r"D:\Document\doing")
print('完成')

url_1 = "http://data.eastmoney.com/DataCenter_V3/jgdy/gsjsdy.ashx?pagesize=50&page="
page=str(1)
url_2 = "&param=&sortRule=-1&sortType=0"
url = url_1+page+url_2
response = requests.get(url,headers= header)
jsontext = json.loads(response.text)
print('完成')

df_date = pd.DataFrame(jsontext['data'])
df_date.head(5)

for page in np.arange(2,1060,1):
    time.sleep(1)
    url = url_1+str(page)+url_2
    res = requests.get(url,headers = header)
    jsontext = json.loads(res.text)
    df_date = pd.concat([df_date, pd.DataFrame(jsontext['data'])])
    df_date.to_csv("东方财富机构调研数据.csv")



df_date.to_csv("东方财富机构调研数据.csv")